﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using System.Collections.Specialized;
using Jalal.Library.Utility;
using BCGC.BLL.BusinessObject.UserAccount;

public partial class Complete : PublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ExtendedSessionManager.CurrentRegistrationStep != RegistrationStep.Complete)
        {
            if (ExtendedSessionManager.CurrentRegistrationStep == RegistrationStep.Confirm)
                Response.Redirect(CustomSiteMap.RegistrationConfirmation);
            else if (ExtendedSessionManager.CurrentRegistrationStep == RegistrationStep.Input)
                Response.Redirect(CustomSiteMap.Register);
            else
                Response.Redirect(CustomSiteMap.Home);
        }
        InitControls();
        SendRegistrationMail();
    }

    private void InitControls()
    {
        hlkGoToLoginPage.NavigateUrl = CustomSiteMap.Login;
    }

    private void SendRegistrationMail()
    {
        StringDictionary registrationInfo = ExtendedSessionManager.RegistrationInformation;
        try
        {
            if (SiteUser.SendRegistrationMail(Security.BindStringInput(registrationInfo["Username"], SecurityLevel.Three),
                Security.BindStringInput(registrationInfo["Password"], SecurityLevel.Three),
                Security.BindStringInput(registrationInfo["Email"], SecurityLevel.Three),
                Security.BindStringInput(registrationInfo["VerificationCode"], SecurityLevel.Three)))
            {
                ltlMailNotificationMessage.Text = "An Email has been sent in your email address ( "
                + Server.HtmlEncode(registrationInfo["Email"]) + " ). The mail"
                + " will guide you to complete your registration process ( Please check bulk folder also ) "
                + ". Thank you.";
                btnResendRegistrationMail.Visible = false;
                hlkGoToLoginPage.Visible = true;
            }
            else
            {
                ltlMailNotificationMessage.Text = @"Your account has been created, but sending registration mail failed. 
                Try to send the registration mail again using the following button. If the problem is not solved, contact admin 
                by providing your login username and registration email address.";
                ExtendedSessionManager.RegistrationInformation = registrationInfo;
                btnResendRegistrationMail.Visible = true;
                hlkGoToLoginPage.Visible = false;
            }
        }
        catch (Exception ex)
        {
            ltlMailNotificationMessage.Text = @"Your account has been created, but sending registration mail failed. 
            Try to send the registration mail again using the following button. If the problem is not solved, contact admin 
            by providing your login username and registration email address.";
            ExtendedSessionManager.RegistrationInformation = registrationInfo;
            btnResendRegistrationMail.Visible = true;
            hlkGoToLoginPage.Visible = false;
        }
    }

    protected void ResendRegistrationMail_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            SendRegistrationMail();
        }
    }
}
